require 'Common/define'
require 'Logic/Config'
require 'Common/functions'

ArenaSpecialBattleItem = {};
HelperFunc.SetUIEnv(ArenaSpecialBattleItem)
local this = ArenaSpecialBattleItem;
this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;

this.txtHot = nil;
this.objPlayerHead = nil;
this.txtPlayerName = nil;
this.txtPlayerScore = nil;
this.objOppoHead = nil;
this.txtOppoName = nil;
this.txtOppoScore = nil;


function ArenaSpecialBattleItem.Init()--todo 应该小写 暂时先大写
    local name, packageName = getUIName(PanelNames.ArenaSpecialBattleItem);
    panelMgr:Push(name, packageName, this.onCreate,Config.useLocalUI);
end

function ArenaSpecialBattleItem.onCreate(obj)
    --obj:SetActive(false);
end

--- 初始化控件
--- @param obj GObject 节点
--- @param data BattleRecord 战斗记录
function ArenaSpecialBattleItem.initData(obj, data)
    winStateController  = obj:GetController("state");
    txtHot = obj:GetChild("Hot");
    objPlayerHead = obj:GetChild("PlayerHead"):GetChild("head"):GetChild("HeadIcon");
    txtPlayerName = obj:GetChild("txtPlayerName");
    txtPlayerScore = obj:GetChild("txtPlayerScore");
    objOppoHead = obj:GetChild("OppoHead"):GetChild("head"):GetChild("HeadIcon");
    txtOppoName = obj:GetChild("txtOppoName");
    txtOppoScore = obj:GetChild("txtOppoScore");
    txtChangePlayerScore = obj:GetChild("playerScore");
    txtChangeAddOppScore = obj:GetChild("oppScore");

    winStateController.selectedIndex = data.win ==1 and 0 or 1;
    txtHot.text = getNumString(data.hots or 0);
    txtPlayerName.text= data.attacker.playerName;
    txtOppoName.text = data.defender.playerName;
    txtPlayerScore.text = tostring(data.attacker.score);
    txtOppoScore.text = tostring(data.defender.score);
    txtChangePlayerScore.text = (data.win == 1 and "+" or "-")..tostring(data.addScore);
    txtChangeAddOppScore.text = (data.win == 1 and "-" or "+")..tostring(data.addScore);

    local dataPlayerHead = {
        icon = logicMgr.HeroManager.GetHeroConfigbyModelId(data.attacker.pic).f_HeroIcon,
        state = EnumConst.HeroHeadStateEnum.NONE
    }
    local dataOppoHead = {
        icon = logicMgr.HeroManager.GetHeroConfigbyModelId(data.defender.pic).f_HeroIcon,
        state = EnumConst.HeroHeadStateEnum.NONE
    }
    objPlayerHead.url = "ui://ICONAtlas/"..dataPlayerHead.icon;

    objOppoHead.url = "ui://ICONAtlas/"..dataOppoHead.icon;
end

return ArenaSpecialBattleItem;
